package com.seafwg.commonutils;

import io.swagger.annotations.ApiModel;
import lombok.Data;

import java.util.HashMap;
import java.util.Map;

@Data
@ApiModel(value = "RC对象",description = "JSON格式统一返回结果集")
public class RC {
    private Boolean success;
    private Integer code;
    private String message;
    private Map<String, Object> data = new HashMap<String, Object>();

    // 私有构造方法
    private RC() {}

    // 提供静态方法访问
    public static RC ok() {
        RC rc = new RC();
        rc.setSuccess(true);
        rc.setCode(ResultCode.SUCCESS);
        rc.setMessage("成功");
        return rc;
    }
    public static RC error() {
        RC rc = new RC();
        rc.setSuccess(false);
        rc.setCode(ResultCode.ERROR);
        rc.setMessage("失败");
        return rc;
    }

    // 提供链式访问方法
    public RC success(Boolean success) {
        this.setSuccess(success);
        return this;
    }
    public RC code(Integer code) {
        this.setCode(code);
        return this;
    }
    public RC message(String message) {
        this.setMessage(message);
        return this;
    }
    public RC data(String key, Object value) {
        this.data.put(key, value);
        return this;
    }
    public RC data(Map<String, Object> map) {
        this.setData(map);
        return this;
    }
}
